#include "types.h"
#include "defs.h"
#include "param.h"
#include "mmu.h"
#include "proc.h"
#include "x86.h"
#include "traps.h"
#include "spinlock.h"
#include "gui.h"

static unsigned short *VESA_ADDR = (unsigned short*)0xe0000000;

void 
draw_loading()
{
  int i;
  int j;
  for(i = 0; i < SCREEN_X_MAX;++i)
  {
    for(j = 0; j < SCREEN_Y_MAX;++j)
    {
      unsigned int offset = j * SCREEN_X_MAX + i;
      unsigned short a = 2;
      *(VESA_ADDR + offset) = (a << 5);
    }
  }
}

void
kbd_response()
{
  int i;
  int j;
  for(i = 0; i < SCREEN_X_MAX;++i)
  {
    for(j = 0; j < SCREEN_Y_MAX;++j)
    {
      unsigned int offset = j * SCREEN_X_MAX + i;
      unsigned short a = 2016;
      *(VESA_ADDR + offset) = a;
    }
  }
}

void
mouse_response(int event, int x_position, int y_position, int x_drag_start, int y_drag_start)
{
  unsigned short a = 2016;
  if(event == 1)
  {
    //cprintf("event1\n");
    a = a << 6;
  }
  else if(event == 2)
  {
    //cprintf("event2\n");
    a = a >> 6;
  }

  //draw mouse
  //cprintf("%d, %d\n", x_position, y_position);
  draw_loading();
  int i, j;
  for(i = 0; i < 5; i++)
  {
    for(j = 0; j < 5; j++)
    {
      unsigned int offset = (y_position + j) * SCREEN_X_MAX + (x_position + i);
      *(VESA_ADDR + offset) = 2016;
    }
  }
}